package com.example.modelsystem.controller;

import com.example.modelsystem.dao.ContactMapper;
import com.example.modelsystem.entity.ContactEntity;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "联系人列表")
@RestController
public class ContactController {

    @Autowired
    ContactMapper contactMapper;

    @ApiOperation(value = "获取联系人列表", notes = "返回列表内容")
    @ApiImplicitParam(paramType = "path", required = true, name = "userId", value = "用户Id", defaultValue = "1")
    @ApiResponses({
            @ApiResponse(code = 422, message = "用户Id不能为空"),
            @ApiResponse(code = 200, message = "获取成功", response = ContactEntity.class)
    })
    @GetMapping("/contact-list/{userId}")
    public ResponseEntity getContactList(@PathVariable Integer userId) {
        if (userId == null) {
            return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body("用户Id不能为空");
        }
        List<ContactEntity> data =contactMapper.selectByUserId(userId);
        return ResponseEntity.status(HttpStatus.OK).body(data);
    }
}
